package com.oa.service.impl;

import com.oa.vo.Page;
import com.oa.pojo.Student;
import com.oa.mapper.StudentMapper;
import com.oa.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public void addStudent(Student student) {
        studentMapper.addStudent(student);
    }

    @Override
    public void delStudent(Integer studentId) {
        studentMapper.delStudent(studentId);
    }

    @Override
    public void updateStudent(Student student) {
        studentMapper.updateStudent(student);
    }

    @Override
    public List<Student> getStudentList() {
        return studentMapper.getStudentList();
    }

    @Override
    public Page getStudentPage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Student> studentList = studentMapper.getStudentList();
        Page page = new Page();
        PageInfo<Student> pageInfo = new PageInfo<>(studentList);
        page.setPageCount(pageInfo.getPages());
        page.setCount(pageInfo.getTotal());
        page.setObject(pageInfo.getList());
        return page;
    }

    @Override
    public Student getStudent(Integer studentId) {
        return studentMapper.getStudent(studentId);
    }
}
